#include "usintl_kbdec.h"
#include <udri.h>
#include <stdio.h>
dri_driver_descriptor_t dri_desc;
uint32_t sigfile_lock = 0;
uint32_t sigfile_write(struct vfs_node *node ,uint8_t *buffer ,uint32_t offset ,uint32_t length,uint32_t fflags){
	sigfile_lock = 1;
	process_keystrokes();
	return 0;
}

uint32_t sigfile_read(struct vfs_node *node ,uint8_t *buffer ,uint32_t offset ,uint32_t length,uint32_t fflags){
	while(!sigfile_lock) for(int wait=0;wait < 1000;wait++) __asm {nop};//TODO:Sleep
	sigfile_lock = 0;
	return 0;
}

int main(int argc,char **argv){
	printf("Loading US-International keyboard map...");
	/* Set up DRI descriptor */
	strcpy(dri_desc.driver_name,"USINTL Decoder");
	dri_desc.driver_magic = DRI_DRIVER_MAGIC;
	dri_desc.driver_class = DRI_CLASS_CHAR;
	dri_desc.driver_id    = 1;
	dri_desc.driver_class_desc = (void *) 0;
	/* Register driver with DRI */
	dri_register_driver(&dri_desc);
	/* Register devfs files */
	dri_register_specfile("kbdsig",VFS_CHARDEVICE_FLAG,0,0x1B6,sigfile_read,sigfile_write);
	/* Initialize driver */
	if (initialize_decoder() == 0){
		printf("OK\n");
		return 0;
	} else
		return -1;
}

